package org.reference.generic;


import java.util.List;

import org.reference.generic.base.Item;
import org.reference.generic.base.Manager;
import org.reference.generic.base.Parameter;
import org.reference.generic.base.ReferenceParameter;
import org.reference.generic.information.Gene;
import org.reference.generic.work.MachineManager;
import org.reference.generic.work.Schedule;
import org.reference.generic.work.Schedule.OnCompleteListenner;

import util.Log;



/**
 * 
 */
public class Process extends Manager implements Schedule.OnCompleteListenner  {

    /**
     * 
     */
    public Process( ) {
    	
    	
    }

    /**
     * 
     */
    private MachineManager machineManager;

    /**
     * 
     */
    private Parameter crossOverRate;

    /**
     * 
     */
    private Parameter referenceCmax;

    /**
     * 
     */
    private Parameter mutationRate;

    /**
     * 
     */
    private Parameter reproductionRate;

    /**
     * 
     */
    private Parameter maxDepth;
    
    /**
     * 
     */
    private Parameter arity;
  
    Schedule sc = new Schedule();
    
   // Map<String, Parameter> params = new HashMap<String, Parameter>();
    
  
    
    private OnCompleteListenner onCompleteListenner;
    /**
     * @param onCompleteListenner
     */
    public void setOnCompleteListenner(OnCompleteListenner onCompleteListenner) {
        this.onCompleteListenner = onCompleteListenner;
    }
    
    
    
  
	@Override
	public void init(Parameter parameters, List<ReferenceParameter> rpList ) {

		
	}

				
	@Override
	public void getResult() {
		
		//System.out.println("스케줄 "+sc.getIndex()+" fitness value(Cmax)" +getFitness());
		

	}
	
    
	
	
	public void makeSchedule(int index, Parameter parameters, List<ReferenceParameter> rpList, Gene gene ){
		
		sc.setOnCompleteListenner(this);
		sc.scheduleParameter(index, parameters, rpList, gene);
	}
	
	public void run(){
		sc.run();
	}
	

	public double getFitness(){
		
		return sc.getFitness();
	}
	
	public interface OnCompleteListenner {
        /**
         * @param 
         */
        public abstract void onComplete(Process process);

    }
	
	@Override
	public void onComplete(Schedule schedule) {

	//System.out.println("프로세스에서 찍은 씨맥스 값 " + getFitness());
	
	//onComplete(schedule);
		
	if (onCompleteListenner == null) return;
    
	onCompleteListenner.onComplete(this);  
	
	
	getResult();
	}




	public Schedule getSc() {
		return sc;
	}



	
}